package com.yc.config;

import dev.langchain4j.mcp.McpToolProvider;
import dev.langchain4j.mcp.client.DefaultMcpClient;
import dev.langchain4j.mcp.client.McpClient;
import dev.langchain4j.mcp.client.transport.McpTransport;
import dev.langchain4j.mcp.client.transport.stdio.StdioMcpTransport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
public class McpConfig {

    @Value("${mcp.baidu-map.api-key}")
    private String baiduMapApiKey;

    @Value("${mcp.amap-maps.api-key}")
    private String amapMapsApiKey;

//    @Bean
//    public McpClient baiduMapMcpClient() {
//        Map<String, String> environment = new HashMap<>();
//        environment.put("BAIDU_MAP_API_KEY", baiduMapApiKey);
//
//        McpTransport transport = new StdioMcpTransport.Builder()
//                .command(Arrays.asList("npx", "-y", "@baidumap/mcp-server-baidu-map"))
//                .environment(environment)
//                .logEvents(true)
//                .build();
//
//        return new DefaultMcpClient.Builder()
//                .transport(transport)
//                .build();
//    }

    @Bean
    public McpClient amapMapsMcpClient() {
        Map<String, String> environment = new HashMap<>();
        environment.put("AMAP_MAPS_API_KEY", amapMapsApiKey);

        McpTransport transport = new StdioMcpTransport.Builder()
                .command(Arrays.asList("C:\\\\Program Files\\\\nodejs\\\\npx.cmd", "-y", "@amap/amap-maps-mcp-server"))
                .environment(environment)
                .logEvents(true)
                .build();

        return new DefaultMcpClient.Builder()
                .transport(transport)
                .build();
    }

    @Bean
    public McpToolProvider mcpToolProvider(McpClient amapMapsMcpClient) {
    //public McpToolProvider mcpToolProvider(McpClient baiduMapMcpClient, McpClient amapMapsMcpClient) {
        return McpToolProvider.builder()
                //.mcpClients(List.of(baiduMapMcpClient, amapMapsMcpClient))
                .mcpClients(List.of(amapMapsMcpClient))
                .build();
    }
}